/**
 * @description 左右滑动组件
 * @author captern
 */
let startX
let startY
let checkIndex
class touchMove {
  constructor() {
  }
  _touchstart (e) {
    checkIndex = e.currentTarget.dataset.index
    startX = e.changedTouches[0].clientX
    startY = e.changedTouches[0].clientY
  }
  _touchmove (e) {
    const touchMoveX = e.changedTouches[0].clientX
    const touchMoveY = e.changedTouches[0].clientY
    const angle = this._angle({
      X: startX,
      Y: startY
    }, {
      X: touchMoveX,
      Y: touchMoveY
    });
    if (Math.abs(angle) > 30) return {
      index: checkIndex,
      type: 'noMove'
    };
    if (touchMoveX < (startX - 30)) {
      return {
        index: checkIndex,
        type: 'moveLeft'
      }
    } else if (touchMoveX > (startX + 30)) {
      return {
        index: checkIndex,
        type: 'moveRight'
      }
    } else {
      return {
        index: checkIndex,
        type: 'noMove'
      }
    }
  }
  _angle (start, end) {
    var _X = end.X - start.X,
      _Y = end.Y - start.Y
    //返回角度 /Math.atan()返回数字的反正切值
    return 360 * Math.atan(_Y / _X) / (2 * Math.PI);
  }
}
export default touchMove